package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.commons.ServerResponse;
import com.chixing.commons.TokenUtil;
import com.chixing.pojo.EducationalExperience;
import com.chixing.mapper.EducationalExperienceMapper;
import com.chixing.pojo.LoginPerson;
import com.chixing.pojo.PersonCenter;
import com.chixing.service.IEducationalExperienceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 教育经历表 服务实现类
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@Service
public class EducationalExperienceServiceImpl implements IEducationalExperienceService {

    @Autowired(required = false)
    private EducationalExperienceMapper experienceMapper;



    //Myresume表获得myresumeId
    @Override
    public EducationalExperience getEduById(Integer myresumeId) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("myresume_id",myresumeId);
//        根据myresumeId查得结果
        List<EducationalExperience> eduList = experienceMapper.selectList(wrapper);
        System.out.println("myserviceImpl-personAll>>>>>"+ eduList.get(0));//获取list第一条信息
        EducationalExperience experience = eduList.get(0);
        System.out.println("==============EducationalExperienceServiceImpl-getEduById==================");

        return experience;
    }

    @Override
    public ServerResponse updateEducational(EducationalExperience educational, Integer myresumeId) {
        QueryWrapper<EducationalExperience> wrapper = new QueryWrapper<>();
        wrapper.eq("myresume_id",myresumeId);
        EducationalExperience experienceSql = experienceMapper.selectOne(wrapper);

        experienceSql.setEducationalName(educational.getEducationalName());
        experienceSql.setEducationalTypeOfSchooling(educational.getEducationalTypeOfSchooling());
        experienceSql.setEducationalEducation(educational.getEducationalEducation());
        experienceSql.setEducationalMajor(educational.getEducationalMajor());
        experienceSql.setEducationalSchoolPeriod(educational.getEducationalSchoolPeriod());
        experienceSql.setEducationalAssociationActivity(educational.getEducationalAssociationActivity());

        int educationalUpdate = experienceMapper.updateById(experienceSql);
        if (educationalUpdate>0){
            return ServerResponse.success("EducationalExperience表修改成功",null);
        }
        return ServerResponse.fail("EducationalExperience表修改失败",null);
    }
}
